home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / ClassEditor.0.4 / Source / RZBrowserCell.subproj / RZSimpleString.m < prev    next >
Encoding:
Text File  |  1995-04-04  |  1.1 KB  |  67 lines

  1. /* 
  2.  * RZSimpleString - a lightweight, archivable, immutable string class
  3.  *
  4.  * You may freely copy, distribute and reuse the code in this example.
  5.  * This code is provided AS IS without warranty of any kind, expressed 
  6.  * or implied, as to its fitness for any particular use.
  7.  *
  8.  * Copyright 1995 Ralph Zazula (rzazula@next.com).  All Rights Reserved.
  9.  *
  10.  */
  11.  
  12. #import "RZSimpleString.h"
  13. #import <appkit/nextstd.h>            // for NX_FREE
  14. #import <objc/hashtable.h>            // for NXCopyStringBuffer
  15.  
  16. @implementation RZSimpleString
  17.  
  18. - init
  19. {
  20.     [self error:"use -initWith:, not -init"];
  21.     return [self notImplemented:_cmd];
  22. }
  23.  
  24. - initWith:(const char *)format, ...
  25. {
  26.     va_list args;
  27.     static char buf[1024];
  28.     
  29.     if(self = [super init]) {
  30.         va_start(args, format);
  31.         vsprintf(buf, format, args);
  32.         data = buf ? NXCopyStringBuffer(buf) : NULL;
  33.     }
  34.     return self;
  35. }
  36.  
  37. - free
  38. {
  39.     if(data) {
  40.         NX_FREE(data);
  41.         data = NULL;
  42.     }
  43.     
  44.     return [super free];
  45. }
  46.  
  47. - (const char *)string
  48. {
  49.     return data;
  50. }
  51.  
  52. - write:(NXTypedStream *)ts
  53. {
  54.     [super write:ts];
  55.     NXWriteTypes(ts, "*", &data);
  56.     return self;
  57. }
  58.  
  59. - read:(NXTypedStream *)ts
  60. {
  61.     [super read:ts];
  62.     NXReadTypes(ts, "*", &data);
  63.     return self;
  64. }
  65.  
  66. @end
  67.